/* Created on Sep 29, 2010 */
package org.tdwg.codeblitz.model;

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.xml.bind.annotation.XmlRootElement;

/**
 * @author Ian Cottingham
 *
 */
@XmlRootElement(name="file")
public class MediaFile {

	public static final String TABLE_ID = "264861";
	
	private final Logger LOG = Logger.getLogger(MediaFile.class
			.getCanonicalName());

	private String guid;
	private String uri;
	private String date;
	private double lat;
	private double lon;
	
	private String host; 
	private String specimen;
	private String comments;
	
	/* this is the actual Fusion Tables row ID and is needed because the WHERE clause
	 * in an update query has to be the ROWID, not any field 
	 */
	private String rowId; 
	
	public MediaFile() { }
	
	/* this is kind of obfuscated with the array pass, should be refactored */
	public MediaFile(String fusionTablesRow) {
		String[] columns = fusionTablesRow.split(",");
		
		this.guid = columns[0];
		this.uri = columns[1];
		this.date = columns[2];
		
		String[] location = columns[3].replace("\"", "").split(" ");
		if ( location.length != 2 ) { 
			LOG.log(Level.WARNING, "The location string was not valid: "+columns[1]);
		} else { 
			this.lat = Double.parseDouble(location[0]);
			this.lon = Double.parseDouble(location[1]);
		}
				
		this.host = columns[4];
		this.specimen = columns[5];
		this.comments = columns[6]; 
		this.rowId = columns[7];
	}
	
	public String getGuid() {
		return guid;
	}
	
	public void setGuid(String guid) {
		this.guid = guid;
	}
	
	public String getUri() {
		return uri;
	}
	
	public void setUri(String uri) {
		this.uri = uri;
	}
	
	public String getDate() {
		return date;
	}
	
	public void setDate(String date) {
		this.date = date;
	}

	public double getLat() {
		return lat;
	}

	public void setLat(double lat) {
		this.lat = lat;
	}

	public double getLon() {
		return lon;
	}

	public void setLon(double lon) {
		this.lon = lon;
	}
	
	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public String getSpecimen() {
		return specimen;
	}

	public void setSpecimen(String specimen) {
		this.specimen = specimen;
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public String getRowId() {
		return rowId;
	}

	public void setRowId(String rowId) {
		this.rowId = rowId;
	}
}
